﻿package mortal.game.view.rebate.rank
{
    import Message.Public.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.display.*;
    import mortal.common.global.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.view.common.*;
    import mortal.game.view.rebate.openServerSevenDay.data.*;

    public class RebateRankCell extends GCellRenderer
    {
        protected var _numTxt:GTextFiled;
        protected var _nameDes:GTextFiled;
        protected var _player:GTextFiled;
        protected var _order:GTextFiled;
        protected var _riseTxt:GTextFiled;
        protected var _rewardTxt:GTextFiled;
        protected var _upgradeArrow:GBitmap;
        protected var _line:ScaleBitmap;
        protected var _rewards:CellsGridSprite;
        protected var _vipIcon:GImageBitmap;
        protected var _powerTxt:GTextFiled;
        private var _rankingData:SToplist;

        public function RebateRankCell()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._numTxt = UIFactory.gTextField("1", 15, 5, 15, 20, this, GlobalStyle.textFormatPutong.setColor(16777215).setSize(13).setBold(true));
            this._nameDes = UIFactory.gTextField("人物名字七个字八", 73, 5, 120, 25, this, GlobalStyle.textFormatPutong.setColor(16777215).setSize(13).center().setBold(true));
            this._player = UIFactory.gTextField("人物名字七个字", 199, 6, 100, 25, this, GlobalStyle.textFormatPutong.setColor(16777215).setSize(13).center().setBold(true));
            this._order = UIFactory.gTextField("22阶", 289, 6, 100, 20, this, GlobalStyle.textFormatPutong.setColor(16777215).setSize(13).center().setBold(true));
            this._riseTxt = UIFactory.gTextField("32", 467, 6, 100, 20, this, GlobalStyle.textFormatPutong.setColor(16777215).setSize(13).center().setBold(true));
            this._rewardTxt = UIFactory.gTextField("王者礼包", 565, 6, 100, 25, this, GlobalStyle.textFormatHuang2.setSize(13).setBold(true));
            this._upgradeArrow = UIFactory.gBitmap(ImagesConst.upgradeArrow, 498, 11, this);
            this._line = UIFactory.bg(-3, 36, 734, 1, this, ImagesConst.SplitLine);
            this._rewards = UIFactory.getUICompoment(CellsGridSprite);
            this._rewards.colNum = 100;
            this._rewards.vCellWid = 25;
            this._rewards.hCellWid = 100;
            this._rewards.genCellFun = this.genItems;
            this._rewards.genCells(3);
            this._rewards.x = 621;
            this._rewards.y = 6;
            this.addChild(this._rewards);
            this._vipIcon = UIFactory.gImageBitmap("vipSmallIcon_9.png", 33, 7, this);
            this._powerTxt = UIFactory.gTextField("12346", 381, 6, 100, 20, this, GlobalStyle.textFormatPutong.setColor(16777215).setSize(13).center().setBold(true));
            return;
        }// end function

        private function genItems() : RebateRankItemSp
        {
            var _loc_1:* = UIFactory.getUICompoment(RebateRankItemSp);
            _loc_1.scaleX = 0.6;
            _loc_1.scaleY = 0.6;
            return _loc_1;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._numTxt = null;
            this._nameDes = null;
            this._player = null;
            this._order = null;
            this._riseTxt = null;
            this._rewardTxt = null;
            this._upgradeArrow = null;
            this._line = null;
            this._rewards = null;
            this._vipIcon = null;
            this._powerTxt = null;
            return;
        }// end function

        private function clear() : void
        {
            this._numTxt.text = "";
            this._upgradeArrow.bitmapData = null;
            this._nameDes.text = "";
            this._player.text = "";
            this._order.text = "";
            this._riseTxt.text = "";
            this._rewardTxt.text = "";
            this._vipIcon.bitmapData = null;
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            super._data = param1;
            this.clear();
            this._rankingData = param1 as SToplist;
            if (this._rankingData == null)
            {
                return;
            }
            this.setNum();
            if (this._rankingData.vip != 0)
            {
                this._vipIcon.visible = true;
                this._vipIcon.imgUrl = GameDefConfig.instance.getVipLevelIconUrl(this._rankingData.vip, 1);
            }
            else
            {
                this._vipIcon.visible = false;
            }
            this.setInfo();
            this.setRise();
            this.setReward();
            return;
        }// end function

        private function setNum() : void
        {
            if (this._rankingData.rank == 1)
            {
                this._rewardTxt.defaultTextFormat = GlobalStyle.textFormatHuang2.setSize(13).setBold(true);
                this._rewardTxt.text = "王者礼包";
            }
            else if (this._rankingData.rank == 2 || this._rankingData.rank == 3)
            {
                this._rewardTxt.defaultTextFormat = GlobalStyle.textFormatZi.setSize(13).setBold(true);
                this._rewardTxt.text = "强者礼包";
            }
            else
            {
                this._rewardTxt.defaultTextFormat = GlobalStyle.textFormatlan.setSize(13).setBold(true);
                this._rewardTxt.text = "勇者礼包";
            }
            this._numTxt.text = this._rankingData.rank + "";
            return;
        }// end function

        private function setInfo() : void
        {
            this._order.x = 289;
            switch(this._rankingData.toplistType)
            {
                case EToplistType._EToplistTypePlayerCombat:
                {
                    this._nameDes.text = "";
                    this._player.text = "" + this._rankingData.entityName;
                    this._order.text = "" + this._rankingData.valueOne + "";
                    this._order.x = 289 + 57;
                    this._powerTxt.text = "";
                    break;
                }
                case EToplistType._EToplistTypePlayerLevel:
                {
                    this._nameDes.text = "";
                    this._player.text = "" + this._rankingData.entityName;
                    this._order.text = "" + this._rankingData.valueOne + "";
                    this._powerTxt.text = "" + this._rankingData.valueThree;
                    break;
                }
                case EToplistType._EToplistTypeMountRank:
                {
                    this._nameDes.text = "" + this._rankingData.entityName;
                    this._player.text = "" + this._rankingData.ownerName + "";
                    this._order.text = "" + this._rankingData.valueOne + "";
                    this._powerTxt.text = "" + this._rankingData.valueTwo;
                    break;
                }
                case EToplistType._EToplistTypeWing:
                {
                    this._nameDes.text = "" + this._rankingData.entityName;
                    this._player.text = "" + this._rankingData.ownerName + "";
                    this._order.text = "" + this._rankingData.valueOne + "阶";
                    this._powerTxt.text = "" + this._rankingData.valueTwo;
                    break;
                }
                case EToplistType._EToplistTypeFashion:
                {
                    this._nameDes.text = "" + this._rankingData.entityName;
                    this._player.text = "" + this._rankingData.ownerName + "";
                    this._order.text = "" + this._rankingData.valueOne + "阶";
                    this._powerTxt.text = "" + this._rankingData.valueTwo;
                    break;
                }
                case EToplistType._EToplistTypeWeapon:
                {
                    this._nameDes.text = "" + this._rankingData.entityName;
                    this._player.text = "" + this._rankingData.ownerName + "";
                    this._order.text = "" + this._rankingData.valueOne + "阶";
                    this._powerTxt.text = "" + this._rankingData.valueTwo;
                    break;
                }
                case EToplistType._EToplistTypePetGrowth:
                {
                    this._nameDes.text = "" + this._rankingData.entityName;
                    this._player.text = "" + this._rankingData.ownerName + "";
                    this._order.text = "" + this._rankingData.valueOne + "";
                    this._powerTxt.text = "" + this._rankingData.valueTwo;
                    break;
                }
                case EToplistType._EToplistTypeFightSoul:
                {
                    this._nameDes.text = "" + this._rankingData.entityName;
                    this._player.text = "" + this._rankingData.ownerName + "";
                    this._order.text = "" + this._rankingData.valueOne + "";
                    this._powerTxt.text = "" + this._rankingData.valueTwo;
                    break;
                }
                case EToplistType._EToplistTypeFightMethod:
                {
                    this._nameDes.text = "" + this._rankingData.entityName;
                    this._player.text = "" + this._rankingData.ownerName + "";
                    this._order.text = "" + this._rankingData.valueOne + "";
                    this._powerTxt.text = "" + this._rankingData.valueTwo;
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        private function setRise() : void
        {
            var _loc_1:int = 0;
            if (this._rankingData.lastRank == 0)
            {
                this._riseTxt.text = "--";
            }
            else
            {
                _loc_1 = this._rankingData.rank - this._rankingData.lastRank;
                if (_loc_1 < 0)
                {
                    this._upgradeArrow.bitmapData = GlobalClass.getBitmapData(ImagesConst.upgradeArrow);
                    this._riseTxt.text = Math.abs(_loc_1) + "";
                }
                else if (_loc_1 > 0)
                {
                    this._upgradeArrow.bitmapData = GlobalClass.getBitmapData(ImagesConst.downArrow);
                    this._riseTxt.text = Math.abs(_loc_1) + "";
                }
                else
                {
                    this._riseTxt.text = "--";
                }
            }
            return;
        }// end function

        private function setReward() : void
        {
            var _loc_4:int = 0;
            var _loc_5:RebateRankItemSp = null;
            var _loc_6:SPlayerItem = null;
            var _loc_1:* = this._rankingData.toplistType;
            var _loc_2:* = this._rankingData.rank;
            var _loc_3:* = OpenServerSevenDayUtil.getRandwardByOrder(_loc_1, _loc_2);
            if (_loc_3 && _loc_3.length > 0)
            {
                this._rewards.genCells(_loc_3.length);
                _loc_4 = 0;
                while (_loc_4 < _loc_3.length)
                {
                    
                    _loc_5 = this._rewards.cellArr[_loc_4];
                    _loc_6 = _loc_3[_loc_4];
                    if (_loc_5 && _loc_6)
                    {
                        _loc_5.item.itemData = new ItemData(_loc_6);
                    }
                    _loc_4++;
                }
            }
            return;
        }// end function

        override protected function initSkin() : void
        {
            var _loc_1:* = new GBitmap();
            var _loc_2:* = UIFactory.bg(0, 0, 730, 37, null, ImagesConst.SelectBg);
            this.setStyle("downSkin", _loc_2);
            this.setStyle("overSkin", _loc_2);
            this.setStyle("upSkin", _loc_1);
            this.setStyle("selectedDownSkin", _loc_2);
            this.setStyle("selectedOverSkin", _loc_2);
            this.setStyle("selectedUpSkin", _loc_2);
            return;
        }// end function

    }
}
